﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Ornament.Messages;
using Ornament.Web;
using Ornament.Web.Messages;

namespace Ornament.MVCWebFrame.Controllers
{
    [HandleError, Authorize]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var dao = new JinTai.WebSite.Dao.FashiScheduleDao();
            var items = dao.GetTopSchedule();
            ViewData["fashi"] = items;

            ViewData["金台寺"] = OrnamentContext.Current.MessageManager.Factory.InfoDao.Find("金台寺", 0, 10, false, InfoState.Published);
            ViewData["白衣古寺"] =  OrnamentContext.Current.MessageManager.Factory.InfoDao.Find("白衣古寺", 0, 10, false, InfoState.Published);
            ViewData["隐秀寺"] =  OrnamentContext.Current.MessageManager.Factory.InfoDao.Find("隐秀寺", 0, 10, false, InfoState.Published);
            ViewData["河南禅院"] =  OrnamentContext.Current.MessageManager.Factory.InfoDao.Find("隐秀寺", 0, 10, false, InfoState.Published);
            return View();
        }

        public ActionResult Admin()
        {
            IList<Info> listInfo =
                OrnamentContext.Current.MessageManager.Factory.InfoDao.Find(
                    OrnamentContext.Current.CurrentUser, 10, 0, MessageType.WorkList.ToString());
            ViewData["workList"] = listInfo;
            return View();
        }

      

        public ActionResult GetInfoItems(int pageSize, int pageIndex, string template)
        {
            try
            {
                IList<Info> infos = OrnamentContext.Current.MessageManager.Factory.InfoDao.Find(
                    OrnamentContext.Current.CurrentUser, pageSize, pageIndex);
                var result = new List<string>();
                foreach (Info info in infos)
                {
                    result.Add(info.Show(template));
                }
                return Json(result);
            }
            catch (Exception ex)
            {
                return Json(new ReturnResult(ex, true), JsonRequestBehavior.AllowGet);
            }
        }

        public ActionResult About()
        {
            return View();
        }
    }
}